package _bye_util;

import _bye_util.logintrec.Ref;
import _bye_util.logintrec.TreeNode;
import _bye_util.logintrec.Leaf;

/**
 * 
 * @author kagioglu
 */
public class LogTightIntRecycler implements IntRecycler
{
    private TreeNode child;
    
    public int newInt()
    {
        if ( this.child == null )
        {
            this.child = new Leaf( 0 );
            return 0;
        }
        else
        {
            Ref result = new Ref( -1 );
            this.child = this.child.newInt( 0, this.child.size() + 1, result );
            return result.value;
        }
    }
    
    public void recycleInt( int garbage )
    {
        if ( this.child == null )
        {
            throw new RuntimeException( "empty tree" );
        }
        else
        {
            this.child = this.child.recycleInt( garbage );
        }
    }
}
